<template>
	<view class="page">
		<view class="page-body">
			<!-- 页面主体内容开始 -->
			<vk-data-form
				ref="form1"
				v-model="form1.data"
				:rules="form1.props.rules"
				:action="form1.props.action"
				:form-type="form1.props.formType"
				:columns='form1.props.columns'
				:loading.sync="form1.props.loading"
				:labelWidth="form1.props.labelWidth"
				:footer-show="false"
				@success="formSuccess"
			></vk-data-form>
			<!-- 页面主体内容结束 -->
		</view>
		<view class="page-footer">
			<!-- 页面底部内容开始 -->
			<el-button v-if="page.showBack" plain style="margin-right: 20px;width: 80px;" @click="pageBack" :loading="form1.props.loading">{{ page.cancelText }}</el-button>
			<el-button type="primary" style="width: 80px;" @click="submitForm" :loading="form1.props.loading">{{ page.submitText }}</el-button>
			<!-- 页面底部内容开始 -->
		</view>
		<view class="page-dialog">
			<!-- 页面弹窗内容开始 -->

			<!-- 页面弹窗内容开始 -->
		</view>
	</view>
</template>

<script>
	var vk = uni.vk;									// vk实例
	export default {
		props:{
			localdata:{},
			pageList:{}
		},
		data() {
			// 页面数据变量
			return {
				// init请求返回的数据
				data:{

				},
				page: {
					title: "首页轮播图",
					submitText: "设置",
					cancelText: "返回",
					showBack: false,
					backPage:""
				},
				form1: {
					// 表单请求数据，此处可以设置默认值
					data: {
						
					},
					// 表单属性
					props: {
						// 表单请求地址
						action: "admin/business/sys/dynamicPages.update",
						// 表单字段显示规则
						columns: [
							{ key: "", title: "参数设置", type: "bar-title" },
							{ 
								key:"type", title:"类型", type:"select", 
								data: [
								    { value: "", label: "全部" },
								    { value: "image", label: "图片" },
									{ value: "swiper", label: "轮播" },
									{ value: "grid", label: "九宫格" },
									{ value: "notice", label: "通知" },
									{ value: "text", label: "文本" },
									{ value: "rich-text", label: "富文本" },
									{ value: "button", label: "按钮" }
								]
							},
							{ key:"show", title:"是否显示", type:"switch", activeValue:true, inactiveValue:false },
							{ key: "", title: "轮播图设置", type: "bar-title" },
							{ key: "data", title: "data", type: "object", showLabel: false,
								columns:[
									{ key: "height", title: "轮播图高度", type: "number", width:200, rightText:"rpx", clearable: false },
									{ key:"dotsStyles", title:"轮播图点样式", type:"json", showLabel:true, height: "130px"},
									{
									  key:"list", title:"", type:"array<object>",
									  showAdd:true,
									  showClear:false,
									  showSort:true,
									  // 新增一行时,该行的默认值
									  defaultValue:{
									    pageType:0,
											image:"",
									  },
									  rightBtns:['copy','delete'],
									  // 每行每个字段对应的渲染规则
									  columns:[
									    {
									      key:"image", title:"图片", type:"image", limit:1, width:200,
									      rules:[
									        { required:true, message:"该项不能为空", trigger:["change","blur"] },
									      ]
									    },
											{
												key:"pagePath", title:"选择已有页面", type:"select", placeholder:"请选择", width:200,
												data:()=>{
												  return this.pageList;
												},
												action:"admin/business/sys/pages.getList",
												props:{ list:"rows", value:"url", label:"name" },
												showAll:true,
												watch: ({ value, formData, column, index, $set }) => {
													// 此处演示根据选择的值动态改变text1的值
													$set("page", value);
												}
											},
									    {
									      key:"page", title:"页面地址", type:"text", minWidth:300,
									    }
									  ]
									}
								]
							},
							{ key: "", title: "高级功能", type: "bar-title" },
							{ key:"switch", title:"是否显示源码", type:"switch", activeValue:true, inactiveValue:false },
							{ key:"data", title:"数据源编辑器", type:"json", showLabel:false, showRule:"switch==true" }
						],
						// 表单验证规则
						rules: {

						},
						labelWidth: "100px"
					}
				}
			}
		},
		created(){
			this.form1.data = this.localdata;
		},
		// 监听 - 页面每次【加载时】执行(如：前进)
		onLoad(options = {}) {
			vk = this.vk;
			this.options = options;
			this.init(options);
		},
		// 监听 - 页面【首次渲染完成时】执行。注意如果渲染速度快，会在页面进入动画完成前触发
		onReady(){

		},
		// 监听 - 页面每次【显示时】执行(如：前进和返回) (页面每次出现在屏幕上都触发，包括从下级页面点返回露出当前页面)
		onShow() {

		},
		// 监听 - 页面每次【隐藏时】执行(如：返回)
		onHide() {

		},
		// 函数
		methods: {
			// 页面数据初始化函数
			init(options){

			},
			// 页面跳转
			pageTo(path){
				vk.navigateTo(path);
			},
			// 页面返回
			pageBack(){
				let that = this;
				const pages = getCurrentPages();
				if (pages.length>1 && pages[0].route !== that.$page.route) {
					vk.navigateBack();
				} else if(that.page.backPage) {
					vk.navigateTo(that.page.backPage);
				}
			},
			// 表单重置
			resetForm() {
				this.$refs.form1.resetForm();
			},
			// 表单提交
			submitForm(){
				this.$refs.form1.submitForm();
			},
			// 表单提交成功后的回调
			formSuccess(res){

			}
		},
		// 监听器
		watch:{

		},
		// 计算属性
		computed:{

		}
	}
</script>
<style lang="scss" scoped>

</style>
